package club.janna.concurrency.example.atomic;

import club.janna.concurrency.annotation.ThreadSafe;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.atomic.AtomicReference;

/**
 * AtomicReference例子
 * @Auther: guopanbo
 * @Date: 2018/7/22 11:38
 * @Description:
 */
@Slf4j
@ThreadSafe
public class AtomicReferenceExample {

    public static void main(String[] args) {
        AtomicReference<Integer> atomicReference = new AtomicReference<>(0);
        atomicReference.compareAndSet(0, 1);
        atomicReference.compareAndSet(0, 2);
        atomicReference.compareAndSet(2, 3);
        atomicReference.compareAndSet(1, 4);
        atomicReference.compareAndSet(3, 5);
        atomicReference.compareAndSet(4, 6);
        log.info("value = {}", atomicReference.get());
    }
}
